package users

import (
	"api/internal/respons"
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

// @Summary 短信验证码发送
// @Description 用户通过手机号，发送验证码
// @Tags 认证
// @Accept json
// @Produce json
// @Param data body types.SendSmsReques true "登录信息"
// @Success 200 {object} types.Response
// @Failure 400 {string} types.Response
// @Failure 500 {string} types.Response
// @Router /users/snedSms [post]
type SendSmsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 短信发送
func (l *SendSmsLogic) SendSms(req *types.SendSmsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.UserRpc.SendSms(l.ctx, &userclient.SendSmsRequest{
		Mobile: req.Mobile,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(sms), nil
}
